<template>
  <div class="card-publication" :class="{ 'card-publication--small': small }">
    <div class="publication__head">
      <a
        :href="url"
        target="_blank"
        rel="noopener noreferrer"
        class="publication__img img-wrapper"
      >
        <img :src="image" :alt="alt" />
        <div class="publication__img__mask">
          <div class="publication__img__mask__btn">
            Read
          </div>
        </div>
      </a>
    </div>
    <div
      class="publication__body"
      :class="{ 'is-single-column': singleColumn }"
    >
      <a
        :href="url"
        target="_blank"
        rel="noopener noreferrer"
        class="publication__title line-clamp-2"
        v-if="title"
      >
        {{ title }}
      </a>
      <!-- hide for now
      issue: https://digisalad.monday.com/boards/2131482301/pulses/2136665863 -->
      <!-- <div class="publication__label" v-if="label">
          {{ label }}
      </div> -->
      <div class="publication__date" v-if="date">{{ date }}</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'

defineOptions({
  name: 'CardPublication'
})

interface Props {
  componentProps?: {
    image?: string
    title?: string
    label?: string
    date?: string
    small?: boolean
    url?: string
    alt?: string
  }
  singleColumn?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  componentProps: () => ({}),
  singleColumn: false
})

const image = computed(() =>
  props.componentProps?.image ?? '/images/dummyimage/card-publication.png'
)

const title = computed(() => props.componentProps?.title ?? '')
const label = computed(() => props.componentProps?.label ?? '')
const date = computed(() => props.componentProps?.date ?? '')
const small = computed(() => props.componentProps?.small ?? false)
const url = computed(() => props.componentProps?.url ?? null)
const alt = computed(() => props.componentProps?.alt ?? title.value)
</script>

<style lang="scss" scoped>
.card-publication .publication__head {
  position: relative;
  max-width: 80%;
  margin: 0 auto;
}

.card-publication .publication__head .publication__img {
  display: inline-block;
  padding-bottom: 141.4%;
  cursor: pointer;
  overflow: hidden;
}

.card-publication .publication__head .publication__img img {
  object-fit: contain;
}

@media (min-width: 768px) {
  .card-publication .publication__head .publication__img:hover .publication__img__mask {
    background-color: rgba(0, 0, 0, 0.4);
    opacity: 1;
  }
}

.card-publication .publication__head .publication__img__mask {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  transition: background-color 0.25s ease-out;
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-publication .publication__head .publication__img__mask__btn {
  font-size: 20px;
  line-height: 1.4;
  font-weight: 400;
  text-align: center;
  color: #F5F5F5;
  padding: 6px 10px;
  min-width: 120px;
  border: 1px solid #F5F5F5;
  border-radius: 2px;
}

@media (max-width: 767.98px) {
  .card-publication .publication__head .publication__img__mask__btn {
    min-width: 100px;
  }
}

.card-publication .publication__body .publication__title {
  display: inline-block;
  text-decoration: none;
  font-size: 20px;
  line-height: 1.4;
  font-weight: 700;
  color: #0032A0;
  margin-top: 12px;
}

@media (max-width: 767.98px) {
  .card-publication .publication__body .publication__title {
    font-size: 20px;
    line-height: 1.4;
    font-weight: 400;
    margin-top: 8px;
  }
}

.card-publication .publication__body .publication__label,
.card-publication .publication__body .publication__date {
  font-size: 12px;
  line-height: 1.33;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-publication .publication__body .publication__label {
  color: #0066CC;
  margin-top: 12px;
}

@media (max-width: 767.98px) {
  .card-publication .publication__body .publication__label {
    margin-top: 8px;
  }
}

.card-publication .publication__body .publication__date {
  color: #1a1c20;
  opacity: 0.6;
  margin-top: 4px;
}

@media (max-width: 767.98px) {
  .card-publication .publication__body .publication__date {
    margin-top: 0;
  }
}

.card-publication--small .publication__head .publication__img {
  padding-bottom: 141.4%;
}

.card-publication--small .publication__head .publication__img .publication__img__mask__btn {
  min-width: 100px;
}

@media (max-width: 767.98px) {
  .card-publication--small .publication__head .publication__img .publication__img__mask__btn {
    min-width: 80px;
  }
}

.card-publication--small .publication__body .publication__title {
  font-size: 20px;
  line-height: 1.4;
  font-weight: 400;
  margin-top: 8px;
}

.card-publication--small .publication__body .publication__label {
  margin-top: 8px;
}

.card-publication--small .publication__body .publication__date {
  margin-top: 0;
}
</style>
